﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HitchHikersGuideToTheGalaxy.Models
{
    public class DestinationRepository : HitchHikersGuideToTheGalaxy.Models.IDestinationRepository
    {
        GalaxyDataContext db = new GalaxyDataContext();

        #region Default Add, Delete and save actions

        /// <summary>
        /// Add a Destionation
        /// </summary>
        /// <param name="destination">Destination object</param>
        public void Add(Destination destination)
        {
            db.Destinations.InsertOnSubmit(destination);
        }

        /// <summary>
        /// Delete a destination
        /// </summary>
        /// <param name="destination">Destination object</param>
        public void Delete(Destination destination)
        {
            db.Destinations.DeleteOnSubmit(destination);
        }

        /// <summary>
        /// Save changes to database
        /// </summary>
        public void Save()
        {
            db.SubmitChanges();
        }

        #endregion

        #region Querys

        /// <summary>
        /// Get all Destinations
        /// </summary>
        /// <returns></returns>
        public IQueryable<Destination> FindAllDestinations()
        {
            return db.Destinations;
        }

        /// <summary>
        /// Get a Destination by Id
        /// </summary>
        /// <param name="id">Id of destination</param>
        /// <returns>Destination object</returns>
        public Destination GetDestination(int id)
        {
            return db.Destinations.SingleOrDefault(d => d.Id == id);
        }

        #endregion
    }
}
